perm filename FAKE21.SAI[DOC,TOB] blob sn#234923 filedate 1976-09-01 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00003 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002
C00004 00003	WHILE TRUE DO BEGIN "false_pos"
C00009 ENDMK
C⊗;
comment
	this version has only the test for false positives
	ie finds the 1% and 5% limits for zero signal;
comment
	conf=sqrt(s0sq/(s0sq+n0sq)) ie cosine
	diff=s0sq;
comment 
	generate a lot of zero signal arrays and test with edge operator.
	Save s0sq and n0sq for each in an array.
	Loop over conf:
		Pass through the array and for all events with adequate conf
		histogram scaled s0sq values.
		Pass through the array to find the 1%(n%)value of s0sq=diff from
		the histogram.;


BEGIN "EDGE_TEST"

DEFINE SAFE_ARRAY=1;	comment this makes all arrays safe;
REQUIRE "VISION.2[SYS,TOB]" SOURCE_FILE; comment vision language package;
REQUIRE EDGE_FILE;
REQUIRE EDGE_PRINT;
REQUIRE TV_VARIABLES;
REQUIRE FAKE_FILE;	! file for fake edges;


EJINIT;	! init Hueckel operator;
MODIFY(BITS);
NOISE_FAKE←5.0;
MODIFY(NOISE_FAKE);

WHILE YES("TEST EDGE OPERATOR? ") DO BEGIN "TST_LOOP"
  ASK_FAKE;
  FAKE;
  OP_APPLY(NBHD_FAKE/2,NBHD_FAKE/2); ! try the edge operator on it;
  END "TST_LOOP";

WHILE TRUE DO BEGIN "false_pos"
  INTEGER ENOUGH;
  INTEGER K;
  DEFINE MAX_COUNT=5000;
  REAL_ARRAY N0SQA[1:MAX_COUNT];
  REAL_ARRAY S0SQA[1:MAX_COUNT];
  REAL S0SQ_MAX,S0SQ_SUM;
  ENOUGH←2000;
  MODIFY(ENOUGH);
  IF ENOUGH>MAX_COUNT THEN ENOUGH←MAX_COUNT;

  comment generate a lot of zero signal events and save s0sq,n0sq;
  RATIO_FAKE←0;  ! no signal case;
  DIFF←CONF←0;  ! turn off the cutoffs to reject nothing;
  S0SQ_MAX←0;
  FOR K←1 STEP 1 UNTIL ENOUGH DO BEGIN "ACCUM"
    REPORT_PROGRESS(K,20);
    FAKE;
    EJLI(NBHD_FAKE/2,NBHD_FAKE/2,0,0); ! try the edge operator on it;
    N0SQA[K]←N0SQ;
    S0SQA[K]←S0SQ;
    IF S0SQ>S0SQ_MAX THEN S0SQ_MAX←S0SQ;  ! save max for scaling;
    S0SQ_SUM←S0SQ_SUM+S0SQ;
    END "ACCUM";

  comment for a range of conf values, find the corresponding 1% and 5%
  false positives (above threshold with no edge signal) for fake
  edges whose noise sq and signal sq have been saved;
  WHILE YES(CRLF&"TAILS OF HISTOGRAM? ") DO BEGIN "HIST"
    DEFINE HIST_MAX=1000;
    REAL NOISE_SCALE; ! scales s0sq,n0sq to fit into array;
    REAL NSQ;
    INTEGER ARRAY COUNT[0:HIST_MAX];
    REAL FRACTION_HIST;
    ASK_MODIFY(CRLF&"% LEVEL FOR HISTOGRAM TAILS ",FRACTION_HIST);
    NOISE_SCALE←(HIST_MAX-1)/S0SQ_MAX; ! scaling s0sq values;
    OUTSTR(CRLF&"MEAN S0SQ "&CVG(S0SQ_SUM/ENOUGH));
    PRINT(S0SQ_MAX);
    NSQ←NOISE_SCALE/(NOISE_FAKE↑2);
    FOR CONF←.95 STEP -.05 UNTIL .40 DO BEGIN "CONF_LOOP"
      SHORT REAL CONFSQ;
      INTEGER K;
      CONFSQ←CONF↑2;
      comment now form histograms over scale s0sq values;
      FOR K←0 STEP 1 UNTIL HIST_MAX DO COUNT[K]←0; ! zero histogram;
      FOR K←1 STEP 1 UNTIL ENOUGH DO BEGIN "HIST1"
        INTEGER N;
        SHORT REAL S;
        S←S0SQA[K];
        IF S/(S+N0SQA[K])>CONFSQ THEN BEGIN   ! if above conf;
          N←S*NSQ+.5;
          IF N>HIST_MAX THEN N←HIST_MAX; ! check limits of array;
          COUNT[N]←COUNT[N]+1;
          END;
        END "HIST1";

      comment now find the 1% and 5% levels of the histogram tails;
      BEGIN "TAILS"
        INTEGER K,N,N1,KN1;
        N1←ENOUGH*FRACTION_HIST;
        KN1←HIST_MAX;
        N←0;
        FOR K←HIST_MAX STEP -1 UNTIL 0 DO BEGIN
          N←N+COUNT[K];
          IF N<N1 THEN KN1←K ELSE DONE;
          END;
        TCRLF;PRINT(CONF);
        OUTSTR(" DIFF CUTOFF LIMITS FOR "&CVF(FRACTION_HIST)&" "
          &CVG(KN1/NSQ)&"  "&CVG(KN1/NOISE_SCALE));
        END "TAILS";
      END "CONF_LOOP";
    END "HIST";
  END "false_pos";
END "EDGE_TEST";